using UnityEngine;
using UnityEngine.UI;
using TMPro;

public class UIManager : MonoBehaviour
{
    [Header("玩家状态UI")]
    [SerializeField] private Slider healthSlider;
    [SerializeField] private Slider expSlider;
    [SerializeField] private TextMeshProUGUI levelText;

    [Header("游戏状态UI")]
    [SerializeField] private TextMeshProUGUI timerText; // 新增

    private PlayerStats playerStats;
    private float gameTimer; // 新增

    void Start()
    {
        playerStats = FindObjectOfType<PlayerStats>();
    }

    void Update()
    {
        // --- 新增计时器更新逻辑 ---
        gameTimer += Time.deltaTime;
        int minutes = Mathf.FloorToInt(gameTimer / 60);
        int seconds = Mathf.FloorToInt(gameTimer % 60);
        timerText.text = string.Format("{0:00}:{1:00}", minutes, seconds);
        // --- 结束 ---

        if (playerStats != null)
        {
            // 更新生命条
            healthSlider.maxValue = playerStats.maxHealth;
            healthSlider.value = playerStats.currentHealth;

            // 更新经验条
            expSlider.maxValue = playerStats.requiredExp;
            expSlider.value = playerStats.currentExp;

            // 更新等级文本
            levelText.text = "LV: " + playerStats.level;
        }
    }
}